package com.demo.springboot.book;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;

@SpringBootApplication
public class ServletConfigration {

    @Bean
    public ServletRegistrationBean createBookServlet(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new BookServlet(),"/book.do");
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean createBookFilter(){
        FilterRegistrationBean filter = new FilterRegistrationBean();
        filter.setFilter(new BookFilter());
        filter.setUrlPatterns(Arrays.asList("/book.do"));
        return filter;
    }

    @Bean
    public ServletListenerRegistrationBean createBookListener(){
        ServletListenerRegistrationBean listener = new ServletListenerRegistrationBean(new BookListener());
        return listener;
    }
}
